package com.cpi.basilos.location.converter;

import org.apache.log4j.Logger;

import com.cpi.basilos.location.dto.LocationDTO;
import com.cpi.basilos.location.exception.LocationException;
import com.cpi.basilos.location.view.LocationView;
import com.cs.common.utils.NumberUtil;

public class LocationConverter {
	private static org.apache.log4j.Logger logger = Logger.getLogger(LocationConverter.class);
	public LocationView convertDTOToView(LocationDTO locationDTO)throws LocationException{
		LocationView locationView = null;
		try{
			locationView = new LocationView();
			locationView.setLocationId(Integer.parseInt(locationDTO.getLocationId()));
			locationView.setWarehouseId(locationDTO.getWarehouseId());
			locationView.setCapacity(NumberUtil.convertQuantity(locationDTO.getCapacity()));
			locationView.setStock(NumberUtil.convertQuantity(locationDTO.getStock()));
			if( locationDTO.getStock() == 0 ){
				locationView.setChangeCornType(true);
			}
		}catch( Exception exception ){
			LocationException locationException = null;
			logger.error(exception);
			exception.printStackTrace(System.err);
			locationException = new LocationException(exception,LocationException.LAYER_CONVERTER, LocationException.ACTION_SELECT);
			throw locationException;
		}
		return locationView;
	}
}